--
-- Author: yawei.zhu
-- Date: 2018-06-27 16:40:27
--
local PvpChampionThroneGame = import(".PvpChampionThroneGame")

local PvpChampionSeasonInfo = class("PvpChampionSeasonInfo")

function PvpChampionSeasonInfo:ctor(msg)
	if msg then
		self:read(msg)
	end
end

function PvpChampionSeasonInfo:read(msg)
	local info = msg.info

	self.seasonId = info.SeasonID
	self.openTime = info.openTime
	self.closeTime = info.closeTime
	self.parcipatateTimes = info.ParcipatateTimes
	self.wonTimes = info.WonTimes
	self.awardWonCount = info.AwardWonCount
	self.awardPartCount = info.AwardPartCount

	local game = info.game
	self.throneGame = PvpChampionThroneGame.new()
	self.throneGame:read(game)

	local gameInfos = info.games
	self.throneInfo = {}
	for i, data in ipairs(gameInfos) do
		local value = {}
		value.mode = data.mode
		value.gameType = data.GameType
		value.baseInfo = nil
		if data.baseinfo then
			value.baseInfo = UserBaseInfo.new(data.baseinfo)
		end		

		value.day = value.gameType -- 方便前端展示
		table.insert(self.throneInfo, value)
	end

	table.sort(self.throneInfo, function(a, b)
		return a.day < b.day
	end)


	-- dump(self)
end

function PvpChampionSeasonInfo:test()
	local info = {}
	info.SeasonID = 1
	info.openTime = 1530115200
	info.closeTime = 1532944800
	info.ParcipatateTimes = 10
	info.WonTimes = 8
	info.AwardPartCount = 1
	info.AwardWonCount = 3

	local game = {}
	game.RegOpenTime = 1532275200
	game.RegCloseTime = 1532599200
	game.PrepareTime = 1532599260
	game.BattleStartTime = 1532599320
	game.CloseTime = 1532599900
	game.register = true
	game.teamMemCount = 3

	info.game = game

	local games = {}
	for i = 1, 7 do 
		local value = {}
		value.mode = i
		value.GameType = i

		-- value.baseinfo = UserBaseInfo.new(UD:getAvatarParams())
		value.baseinfo = nil
		table.insert(games, value)
	end
	info.games = games

	self:read({info = info})
end

function PvpChampionSeasonInfo:getTitle()
	return string.format( L("champion_notice4"), self.seasonId)
end

function PvpChampionSeasonInfo:getDateStr()
	local beginDate = os.date("*t", self.openTime)
	local endDate = os.date("*t", self.closeTime)
	return string.format("%d.%d-%d.%d", beginDate.month, beginDate.day, endDate.month, endDate.day)
end

function PvpChampionSeasonInfo:getThroneInfo(day)
	return self.throneInfo[day]
end

function PvpChampionSeasonInfo:getThroneGame()
	return self.throneGame
end

function PvpChampionSeasonInfo:setRegister(register)
	self.throneGame:setRegister(register)
end

function PvpChampionSeasonInfo:getRegister()
	return self.throneGame:getRegister()
end

function PvpChampionSeasonInfo:setMemCount(count)
	self.throneGame:setMemCount(count)
end


return PvpChampionSeasonInfo

